Helpful Information
 
 
Category: DOM and JSON scripting
getAttribute with "this"

help,

i make function like this:

function chrCount(which){
maxChr = document.getElementById(which.name).getAttribute('maxlength');
if (which.value.length > maxChr)
which.value = which.value.substring( 0 , maxChr )
else
document.getElementById('chrLeft').innerHTML = maxChr-which.value.length + " chr(s)Left" ;
}

html code:

<input name="name" type="text" maxlength="8" onKeyDown="chrCount(this)" onKeyUp="chrCount(this)">
<div id="chrLeft" ></div>

above code work in IE6, not in Mozilla, can anybody tell the right code ? running in IE6 and DOM browser only is find.
Thanks

You are passing getElementById a name, not an id. Huge difference in terms of DOM.

Anyway, since you're passing the this reference:
maxChr = which.getAttribute('maxlength');

Is much clearer, faster, and less haphazard. :)

u r right!!! Why was I so stupid!! thx a lots...










privacy (GDPR)